<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>HouDun许愿墙</title>
	<link rel="stylesheet" href="__PUBLIC__/Css/index.css" />
	<script type="text/javascript" src='__PUBLIC__/Js/jquery-1.7.2.min.js'></script>
	<script type="text/javascript" src='__PUBLIC__/Js/index.js'></script>
</head>
<body>
	<div id='top'>
		<span id='send'></span>
	</div>
	<div id='main'>
	<volist name="wishlist" id="vo"> 
		<dl class='paper a{$vo['color']}'>
			<dt>
				<span class='username'>{$vo['username']}</span>
				<span class='num'>{$vo['num']}</span>
			</dt>
			<dd class='content'>{$vo["content"] | phiz_replace }</dd>
			<dd class='bottom'>
				<span class='time'>{:date("Y-m-d H:i",$vo['time_at'])}</span>
				<a href="" class='close'></a>
			</dd>
		</dl>
	</volist>
	</div>

	<div id='send-form'>
		<p class='title'><span>许下你的愿望</span><a href="" id='close'></a></p>
		<form action="" name='wish' method="POST">
			<p>
				<label for="username">昵称：</label>
				<input type="text" name='username' id='username'/>
			</p>
			<p>
				<label for="content">愿望：(您还可以输入&nbsp;<span id='font-num'>50</span>&nbsp;个字)</label>
				<textarea name="content" id='content'></textarea>
				<div id='phiz'>
					<img src="__PUBLIC__/Images/phiz/zhuakuang.gif" alt="抓狂" />
					<img src="__PUBLIC__/Images/phiz/baobao.gif" alt="抱抱" />
					<img src="__PUBLIC__/Images/phiz/haixiu.gif" alt="害羞" />
					<img src="__PUBLIC__/Images/phiz/ku.gif" alt="酷" />
					<img src="__PUBLIC__/Images/phiz/xixi.gif" alt="嘻嘻" />
					<img src="__PUBLIC__/Images/phiz/taikaixin.gif" alt="太开心" />
					<img src="__PUBLIC__/Images/phiz/touxiao.gif" alt="偷笑" />
					<img src="__PUBLIC__/Images/phiz/qian.gif" alt="钱" />
					<img src="__PUBLIC__/Images/phiz/huaxin.gif" alt="花心" />
					<img src="__PUBLIC__/Images/phiz/jiyan.gif" alt="挤眼" />
				</div>
			</p>
			<span id='send-btn'></span>
			
		</form>
	</div>
	
<!--[if IE 6]>
    <script type="text/javascript" src="__PUBLIC__Js/iepng.js"></script>
    <script type="text/javascript">
        DD_belatedPNG.fix('#send,#close,.close','background');
    </script>
<![endif]-->
		<script type="text/javascript">
				$(document).ready(function(){
					// 获取send按钮
					btn = $('#send-btn');
					// console.log(btn);
					// 按钮点击响应事件处理
					btn.click(function(){
						URL = '{:U("test")}';  // demo/index.php/Home/Index/test
						// username = $('#username'); // 取输出框元素
						username = $('input[name="username"]');  // 结合标签和元素属性来唯一取得元素  :eq(0)
						//console.log(username.val());   //用元素的val()取得元素value属性值
						content  = $('#content');
							if(username.val() == ''){
								alert('用户名不能为空！');
								username.focus();
								return false;
							};
							

							if(content.val() == ''){
								alert('内容不能为空！');
								content.focus();
								return false;
							};
						$.post(URL,{user:username.val(),content:content.val()},
						     function(data){
						     	// 将json字符串转为json对象。
						     	//console.log(data);
						     	//data = eval('(' + data + ')');
						     	//console.log(data.content);
						     	if(data.status==1){
									wish = '';
									wish += '<dl class="paper a' + data.color +'">';
									wish += '<dt><span class="username">' + data.username + '</span>';
									wish += '<span class="num">No.' + data.id + '</span></dt>';
									wish += '<dd class="content">' + data.content + '</dd><dd class="bottom"><span class="time">'
									wish += data.time_at + '</span><a href="" class="close"></a></dd></dl>'	
									$('#main').append(wish);
									$('#close').click();
								}else {
									console.log(data);
									alert(data);
								}
				 });
	});
});


				
		</script>

</body>
</html>